package Thread;

/**
 * @author liyang
 * @version 1.0
 * @package Thread
 * @file ThreadDemo3.java
 * @description
 * @time 2024-04-05 17:00
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //直接继承Thread并重写run方法形式
        Thread t1 = new Thread(){
            @Override
            public void run(){
                String name = getName();//获取t1线程的名字
                System.out.println(name);
                for(int i=0;i<1000;i++){
                    System.out.println("你是谁啊？");
                }
            }
        };

        //实现Runnable接口重写run方法形式
//        Runnable r2 = new Runnable() {
//            @Override
//            public void run() {
//                for (int i=0;i<1000;i++){
//                    System.out.println("我是查水表的!");
//                }
//            }
//        };
//        Thread t2 = new Thread(r2);

        //lambda表达式写法
        Thread t2 = new Thread(()->{
            for (int i=0;i<1000;i++){
                System.out.println("我是查水表的!");
            }
        });

        t1.start();
        t2.start();


    }
}
